
#ifndef WISHMASTER_TASKSAVETHREAD_H
#define WISHMASTER_TASKSAVETHREAD_H

#include <QObject>
#include "task.h"
#include "components/threadptr.h"
#include "components/chan.h"
#include "components/attachment.h"
#include "components/postid.h"
#include "threadbuilder.h"
#include <QHash>

namespace Wishmaster
{
	class ThreadSaver;
	class TaskAttachmentRequest;
	class TaskSaveThread : public Task
	{
		Q_OBJECT
	public:
		TaskSaveThread(const ThreadPtr& thread, Connector* connector, Taskhub* hub, ThreadBuilderPtr builder, const QString& path, const QString& msg);
		virtual ~TaskSaveThread();

		virtual void start();
		virtual void cancel();

	private slots:
		void requestDone(TaskAttachmentRequest* task, const QByteArray& arr, const QString& contentType);

	private:
		void doSaving();

		ThreadPtr m_thread;
		Taskhub* m_taskhub;
		ThreadBuilderPtr m_builder;
		Connector* m_connector;
		QString m_path;
		int m_done;
		int m_total;

		typedef QHash<PostId, AttachmentPtr> HashAttachment;
		HashAttachment m_attachs;
	};
}

#endif

